//
//  LSLitenCell.m
//  听说弱点强化训练
//
//  Created by 盛超 on 2018/10/22.
//  Copyright © 2018年 盛超. All rights reserved.
//

#import "LSListenCell.h"

@interface LSListenCell ()

@property (nonatomic,strong) UIButton *optionBtn;
@property (nonatomic,strong) TYAttributedLabel *optionText;

@end

@implementation LSListenCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    
    if (self) {
        
        self.backgroundColor = [UIColor whiteColor];
        
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        
        UIButton *optionBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        optionBtn.userInteractionEnabled = NO;
        self.optionBtn = optionBtn;
        [optionBtn setBackgroundImage:[UIImage imageNamed:@"LS-答案原始圆"] forState:UIControlStateNormal];
        [self addSubview:optionBtn];
        [optionBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self).offset(25);
            make.top.equalTo(self).offset(2);
            make.size.mas_equalTo(CGSizeMake(30, 30));
        }];
        
        TYAttributedLabel *optionText = [[TYAttributedLabel alloc] init];
        optionText.numberOfLines = 0;
        optionText.characterSpacing= 2;
        optionText.linesSpacing = 5;
        self.optionText = optionText;
        optionText.font = [UIFont systemFontOfSize:17.0f];
        [self addSubview:optionText];
        optionText.frame = CGRectMake(70,7,kWidth-100,20);
    }
    
    return self;
}

- (void)setModel:(LSOption *)model {
    _model = model;
    [_optionBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [_optionBtn setTitle:_model.OptionIndex forState:UIControlStateNormal];
    if (![_model.OptionContent isEqualToString:@""]) {
        //_optionText.attributedText = [_model.OptionContent dr_HtmlStringWithFontSize:17.0f];
        _optionText.attributedText = [_model.OptionContent dr_changeCharSpace:1.5 LineSpace:5 Font:17];
         if(_model.cellHeight) {
              _optionText.frame = CGRectMake(70,7,kWidth-100,_model.cellHeight-10);
         } else {
             [_optionText sizeToFit];
         }
        if(!_model.cellHeight) {
            _model.cellHeight = CGRectGetMaxY(_optionText.frame)+10;
        }
        
    } else {
        
        for (UIImageView *imageView in _optionText.subviews) {
            [imageView removeFromSuperview];
        }
        
        UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(70,7, 100, 70)];
        imageView.backgroundColor = [UIColor whiteColor];
        imageView.image = [UIImage imageWithContentsOfFile:_model.OptionPicture];
        [self addSubview:imageView];
        if(!_model.cellHeight) {
            _model.cellHeight = 80;
        }
    }
    
 
   
}


- (void)setOptionStyle:(LSSelectOptionStyle)optionStyle {
    _optionStyle = optionStyle;
    if(_optionStyle==LSSelectOptionWhite) {
        [self.optionBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        [self.optionBtn setBackgroundImage:[UIImage imageNamed:@"LS-答案原始圆"] forState:UIControlStateNormal];
        
    } else if(_optionStyle==LSSelectOptionBlue) {
        [self.optionBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [self.optionBtn setBackgroundImage:[UIImage imageNamed:@"LS-选中答案背景"] forState:UIControlStateNormal];
        
    } else if(_optionStyle==LSSelectOptionGreen) {
        [self.optionBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [self.optionBtn setBackgroundImage:[UIImage imageNamed:@"LS-选中正确答案背景"] forState:UIControlStateNormal];
        
    } else if(_optionStyle==LSSelectOptionRed) {
        [self.optionBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [self.optionBtn setBackgroundImage:[UIImage imageNamed:@"LS-选中答案错误背景"] forState:UIControlStateNormal];
    }
}

@end
